package com.example.child_protection.service.impl;

import com.example.child_protection.dao.SystemRoleButtonDao;
import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemRoleButtonInsertRequestDTO;
import com.example.child_protection.dto.request.update.SystemRoleButtonUpdateRequestDTO;
import com.example.child_protection.enums.ServiceActionEnums;
import com.example.child_protection.model.AttrValueModel;
import com.example.child_protection.model.SystemRoleButtonModel;
import com.example.child_protection.service.SystemRoleButtonManageService;
import com.example.child_protection.service.base.MyBaseService;
import com.example.child_protection.service.base.MyServiceExecutor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 角色按钮管理service实现层
 * @date 2018-11-2
 * @author Biz
 */
@Component
public class SystemRoleButtonManageServiceImpl extends MyBaseService implements SystemRoleButtonManageService {

    @Autowired
    public SystemRoleButtonDao systemRoleButtonDao;

    /**
     * 添加
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO insert(SystemRoleButtonInsertRequestDTO requestDTO){
        return this.service(ServiceActionEnums.SYSTEM_ROLE_BUTTON_INSERT,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SystemRoleButtonInsertRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SystemRoleButtonInsertRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemRoleButtonModel model = new SystemRoleButtonModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemRoleButtonDao.insert(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 修改
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO update(SystemRoleButtonUpdateRequestDTO requestDTO){
        return this.service(ServiceActionEnums.SYSTEM_ROLE_BUTTON_UPDATE,requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SystemRoleButtonUpdateRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SystemRoleButtonUpdateRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemRoleButtonModel model = new SystemRoleButtonModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemRoleButtonDao.updateSelective(model);
                res.setId(model.getId());
                res.successfully();
                return res;
            }
        });
    }

    /**
     * 删除
     * @param requestDTO
     * @return
     */
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO){
        return this.service (ServiceActionEnums.SYSTEM_ROLE_BUTTON_DELETE, requestDTO, BaseResponseDTO.class, new MyServiceExecutor<SimpleIdRequestDTO, BaseResponseDTO>() {
            @Override
            protected BaseResponseDTO myprocess(SimpleIdRequestDTO requestDTO) throws Exception {
                BaseResponseDTO res = new BaseResponseDTO();
                SystemRoleButtonModel model = new SystemRoleButtonModel();
                BeanUtils.copyProperties(requestDTO,model);
                systemRoleButtonDao.deleteForLogic(model);
                res.setId(requestDTO.getId());
                res.successfully();
                return res;
            }
        });
    }

}
